package chapter02;

import java.math.BigDecimal;

/**
 * 用while循环计算1+1／2！+1／3!...1/20!
 * Created by a on 2017/6/9.
 */
public class Test036 {
    public static void main(String[] args) {
        BigDecimal sum = new BigDecimal(0.0);
        BigDecimal factorial = new BigDecimal(1.0);
        int i = 1;
        while (i<=20){
            sum = sum.add(factorial);
            ++i;
            factorial = factorial.multiply(new BigDecimal(1.0/i));
        }
        System.out.println("计算结果等于:"+sum);
    }

}
